package com.shemy.fileservice.config;

import com.shemy.fileservice.utils.WebUtil;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description IP地址拦截器
 * @Author Dzsom
 * @Date 2018-10-24 7:46
 * @Encoding UTF-8
 * @Version 1.0
 **/
public class AuthorityIPInterceptor extends HandlerInterceptorAdapter {
//    @Resource
//    FileConfig fileConfig;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String ip = WebUtil.getIpAddress(request);
//        System.out.println("ip------------------------:"+ip);
//        String path = request.getServletPath();
//        //不对匹配该值的访问路径拦截（正则）
//        final String NO_INTERCEPTOR_PATH = ".*/((show)).*";
//        if(path.matches(NO_INTERCEPTOR_PATH)){ //允许展示路径
//            return true;
//        }else{
//            //允许ip可以进行上传访问
//            if(Arrays.asList(fileConfig.getIPs()).contains(ip)){
//                return true;
//            }else {
//                return false;
//            }
//        }
//    }
}
